import request from "@/router/axios";
import { Message } from "element-ui";

export const uploadFile = (file, size = 50) => {
  const fileSize = file.size / (1024 * 1024);
  if (fileSize > size) {
    Message({
      message: `文件不能大于${size}MB`,
      type: "warning",
    });
    return Promise.reject({ msg: `文件不能大于${size}MB` });
  }
  let formData = new FormData();
  formData.append("file", file);

  return request({
    headers: { "Content-Type": "multipart/form-data" },
    url: " /api/blade-resource/oss/endpoint/put-file-attach",
    method: "post",
    data: formData,
    timeout: 1000 * 60 * 2,
  });
};



export const preUploadFile = (file, size = 50) => {
  const fileSize = file.size / (1024 * 1024);
  if (fileSize > size) {
    Message({
      message: `文件不能大于${size}MB`,
      type: "warning",
    });
    return Promise.reject({ msg: `文件不能大于${size}MB` });
  }
  let formData = new FormData();
  formData.append("file", file);

  return request({
    headers: { "Content-Type": "multipart/form-data" },
    url: " /api/blade-resource/oss/endpoint/pre-upload",
    method: "post",
    data: formData,
    timeout: 1000 * 60 * 2,
  });
};
